<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr1 = [11, 12, 21, 22, 31, 32];
      const arr2 = [
        { name: "zhangsan", num: 12 },
        { name: "lisi", num: 21 },
        { name: "wangwu", num: 22 },
        { name: "zhaoliu", num: 32 },
      ];
      let newArr = new Array(arr1.length).fill(undefined);

      arr2.forEach((l) => {
        const curValIndex = arr1.findIndex((i) => i === l.num);
        if (curValIndex > -1) {
          newArr[curValIndex] = l;
        }
      });

      console.log(arr1, "--arr1");
      console.log(arr2, "--arr2");
      console.log(newArr, "--newArr");
    </script>
  </body>
</html>
